package com.yehuo.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yehuo.app.entity.Wallet;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

public interface WalletMapper extends BaseMapper<Wallet> {
    @Update({"UPDATE u_wallet w SET w.consumption_amount = ROUND(w.consumption_amount + #{amount},2), w.amount = ROUND(w.amount - #{amount},2), w.update_time = #{date} WHERE ROUND(w.amount - #{amount},2) >= 0 AND w.id = #{id}"})
    int updateAmount(@Param("id") Integer id, @Param("amount") String amount, @Param("date") Date date);

    @Update({"UPDATE u_wallet w SET w.recharge_amount = ROUND(w.recharge_amount + #{amount},2), w.amount = ROUND(w.amount + #{amount},2), w.update_time = #{date} WHERE  w.id = #{id}"})
    int updateAddAmount(@Param("id") Integer id, @Param("amount") String amount, @Param("date") Date date);

    @Select({"SELECT * FROM u_wallet w where w.user_id = #{uid}"})
    Wallet selectByUserId(String uid);
}
